/* 
 * Copyright (c) 2010	All Right Reserved
 * http://www.cndatacom.com
 * Project  kpiPlatform 
 */
package com.fare.taluo.util.excel.engine.operate.impl;

import java.util.Map;

import jxl.write.WritableCellFormat;
import jxl.write.WriteException;

import com.fare.taluo.util.excel.engine.operate.IExcelCellDisplayRugular;


/**
 * 实现单双行显示不同的颜色
 * 
 * @since Oct 20, 2010
 * @author tss
 * @version $Id: ExcelCellDisplayRugularOddAndEvenImp.java,v1.0 Oct 20, 2010
 *          1:57:35 PM tss Exp $
 * 
 */
public class ExcelCellDisplayRugularOddAndEvenImp implements
		IExcelCellDisplayRugular {
	
	/**
	 * 通过实现此方法来实现excel的个性化显示：单双行显示不同的颜色，在excel-config.xml的配置为：
	 * <property regular="class:com.gdcn.kpi.common.excel.engine.operate.impl.ExcelCellDisplayRugularOddAndEvenImp;oddColor:15"/>
	 * 其中regular中的class为必配参数 oddcolor 为奇数行颜色 evenColor 为偶数行颜色
	 * @param c 列数
	 * @param r 行数
	 * @param regularMap 配置信息
	 * @param cf 要设置的单元格格式
	 * @return
	 */
	public WritableCellFormat processCell(int c, int r,
			Map<String, String> regularMap, WritableCellFormat cf) {
		try {
			if (r % 2 == 0) {			
				if (regularMap.get("evencolor") != null) {
					int i = Integer.parseInt(regularMap.get("evencolor"));
					cf.setBackground(jxl.format.Colour.getInternalColour(i));
				}
			} else {
				if (regularMap.get("oddcolor") != null) {
					int i = Integer.parseInt(regularMap.get("oddcolor"));
					cf.setBackground(jxl.format.Colour.getInternalColour(i));
				}
			}

		} catch (WriteException e) {
			e.printStackTrace();
		}
		return cf;
	}

}
